package com.jdk18.stream;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * Created by xuyiwei on 2018/7/4.
 */
public class StreamTest {
    public static void main(String[] args) {

        List<Person> list = new ArrayList();
        list.add(new Person(1, "haha"));
        list.add(new Person(1, "rere"));
        list.add(new Person(3, "fefe"));



//        Map<Integer, Person> mapp = list.stream().collect(Collectors.toMap(Person::getId, Function.identity()));
//
//        System.out.println(mapp);
//
//        System.out.println(mapp.get(1).getName());
//
//        Map<Integer, String> map = list.stream().collect(Collectors.toMap(Person::getId, Person::getName));
//
//        System.out.println(map);

        Map<Integer,String> mappp = list.stream().collect(Collectors.toMap(Person::getId,Person::getName,(a,b)->a));
        System.out.println(mappp.get(1));


        List<String> list1 = new ArrayList<>();
//        list1.add(new Person(4,"aaa"));
    }
}
